package com.ruoyi.Management.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.Management.domain.CaseType;
import com.ruoyi.Management.service.ICaseTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Management.service.ICaseTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案例类型Controller
 * 
 * @author why
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/Management/case_type")
public class CaseTypeController extends BaseController
{
    @Autowired
    private ICaseTypeService caseTypeService;

    /**
     * 查询案例类型列表
     */
    @PreAuthorize("@ss.hasPermi('Management:case_type:list')")
    @GetMapping("/list")
    public TableDataInfo list(CaseType caseType)
    {
        startPage();
        List<CaseType> list = caseTypeService.selectCaseTypeList(caseType);
        return getDataTable(list);
    }

    /**
     * 导出案例类型列表
     */
    @PreAuthorize("@ss.hasPermi('Management:case_type:export')")
    @Log(title = "案例类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaseType caseType)
    {
        List<CaseType> list = caseTypeService.selectCaseTypeList(caseType);
        ExcelUtil<CaseType> util = new ExcelUtil<CaseType>(CaseType.class);
        util.exportExcel(response, list, "案例类型数据");
    }

    /**
     * 获取案例类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('Management:case_type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(caseTypeService.selectCaseTypeById(id));
    }

    /**
     * 新增案例类型
     */
    @PreAuthorize("@ss.hasPermi('Management:case_type:add')")
    @Log(title = "案例类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaseType caseType)
    {
        return toAjax(caseTypeService.insertCaseType(caseType));
    }

    /**
     * 修改案例类型
     */
    @PreAuthorize("@ss.hasPermi('Management:case_type:edit')")
    @Log(title = "案例类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaseType caseType)
    {
        return toAjax(caseTypeService.updateCaseType(caseType));
    }

    /**
     * 删除案例类型
     */
    @PreAuthorize("@ss.hasPermi('Management:case_type:remove')")
    @Log(title = "案例类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(caseTypeService.deleteCaseTypeByIds(ids));
    }
}
